#ifndef TCP_SERVER_COUNTDOWNLATCH_H
#define TCP_SERVER_COUNTDOWNLATCH_H

#include "../noncopyable.h"
#include "Mutex.h"

/**
 * 向下倒计时锁, 初始化的时候设置一个参量
 * 每次调用都会有对应的countDown都会将参量 count_--, 当count_--到0的时候就唤醒所有
 */
class CountDownLatch : muduo::noncopyable {
public:

    explicit CountDownLatch(int count);

    void wait();

    void countDown();

    int getCount() const;

private:
    mutable MutexLock mutex_;
    Condition condition_;
    int count_;
};

#endif //TCP_SERVER_COUNTDOWNLATCH_H
